package com.hdey.controller.max;


import com.hdey.pojo.max.TbUscSupcla;
import com.hdey.service.max.TbUscSupclaSvs;
import com.hdey.utils.Result;
import com.hdey.vo.TbUscSupclaVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
@RequestMapping("/supcla")
@Slf4j
public class TbUscSupclaController {

    @Resource
    private TbUscSupclaSvs tbUscSupclaSvs;

    private String msg;
    //查询
    @RequestMapping("/getSupcla")
    public Result getSupcla(TbUscSupclaVo supclaVo, HttpSession session){
        //System.out.println(supclaVo);
        List<TbUscSupcla> list = tbUscSupclaSvs.getTbUscSupcla(supclaVo.getSupclaId(),supclaVo.getSupclaFlag());
        session.setAttribute("supclaList",list);
        return Result.success(list,list.size());
    }

    //修改
    @RequestMapping("/updateSupcla")
    public Result updateSupcla(TbUscSupcla supcla){
        System.out.println(supcla.toString());

        int result = tbUscSupclaSvs.updateSupcla(supcla);
        if(result>0){
            msg = "修改成功！";
        }else{
            msg = "修改失败！";
        }
        return Result.success(msg);
    }

    //删除
    @RequestMapping("/deleteSupcla")
    public Result deleteSupcla(Integer supclaId){
        //System.out.println(supclaId);
        try {
            tbUscSupclaSvs.deleteSupcla(supclaId);
            msg = "删除成功！";
            return Result.success(msg);
        }catch (Exception e){
            msg = "删除失败！";
            log.error(msg,e);
            return Result.failed(msg);
        }
    }


    //添加
    @RequestMapping("/createSupcla")
    public Result createSupcla(TbUscSupcla supcla){
        System.out.println(supcla);
        try {
            tbUscSupclaSvs.createSupcla(supcla);
            msg = "创建成功！";
            return Result.success(msg);
        }catch (Exception e){
            msg = "创建失败！";
            log.error(msg,e);
            return Result.failed(msg);
        }
    }



}
